import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:wan_android_flutter/common_ui/web/webview_widget.dart';
import 'package:wan_android_flutter/pages/about/about_us_page.dart';
import 'package:wan_android_flutter/pages/auth/login_page.dart';
import 'package:wan_android_flutter/pages/auth/register_page.dart';
import 'package:wan_android_flutter/pages/home/home_page.dart';
import 'package:wan_android_flutter/pages/knowledge/detail/knowledge_detail_tab_page.dart';
import 'package:wan_android_flutter/pages/my_collects/my_collects_page.dart';
import 'package:wan_android_flutter/pages/search/search_page.dart';
import 'package:wan_android_flutter/pages/tab_page.dart';

import '../common_ui/web/webview_page.dart';
import '../repository/datas/knowledge_list_model.dart';

class Routes {
  static Route<dynamic> generateRouter(RouteSettings setting) {
    switch (setting.name) {
      case RoutesPath.tab:
        return pageRoute(TabPage(),settings: setting);
      case RoutesPath.webViewPage:
        return pageRoute(WebViewPage(loadResource: "",webViewType: WebViewType.URL,), settings: setting);
      case RoutesPath.loginPage:
        return pageRoute(LoginPage(), settings: setting);
      case RoutesPath.registerPage:
        return pageRoute(RegisterPage(), settings: setting);
      case RoutesPath.searchPage:
        return pageRoute(SearchPage(), settings: setting);
      case RoutesPath.aboutUsPage:
        return pageRoute(AboutUsPage(), settings: setting);

      case RoutesPath.myCollectsPage:
        return pageRoute(MyCollectsPage(), settings: setting);
      case RoutesPath.knowledgeDetailTabPage:
        final arguments = setting.arguments as Map<String, dynamic>?;
        final tabLists = arguments?['tabs'] as List<KnowledgeChildren>? ?? [];
        return pageRoute(KnowledgeDetailTabPage(tabLists: tabLists), settings: setting);
      default:
        return pageRoute(Scaffold(
          body: SafeArea(
              child: Center(
            child: Text("路由：${setting.name} 不存在"),
          )),
        ));
    }
  }

  static MaterialPageRoute pageRoute(Widget page,
      {RouteSettings? settings,
      bool? fullscreenDialog,
      bool? maintainState,
      bool? allowSnapshotting}) {
    return MaterialPageRoute(
        builder: (context) {
          return page;
        },
        settings: settings,
        fullscreenDialog: fullscreenDialog ?? false,
        maintainState: maintainState ?? true,
        allowSnapshotting: allowSnapshotting ?? true);
  }
}

class RoutesPath {
  static const String tab = "/";
  static const String webViewPage = "/web_view_page";
  static const String loginPage = "/login_page";
  static const String registerPage = "/register_page";
  static const String searchPage = "/search_page";
  static const String knowledgeDetailTabPage = "/knowledge_detail_tab_page";
  static const String myCollectsPage = "/my_collects_page";
  static const String aboutUsPage = "/about_us_page";
  //AboutUsPage

}
